module majiang.Datas {
    /**
     * 游戏进行过程中的数据
     */
    export class Playing {
        static allPoint:number;
        static allGang:number;
        static allFan:number;
        static allHu:number;
        static paiFan:number;
        static paiGang:number;
        static timeMax:number = 180;
        static timeSec:number;
        static shengyuPai:PaiChi; //剩余牌
        static shiyongPai:PaiChi; //已经使用的牌
        static hupaiArea:Array<number>;
        static xuanArea:Array<number>;
        static hupaiJilu:Array<string>;  //胡牌 牌型记录
        static xuanIndexMax:number = 7;  //最大可显示的待选牌数量
        static majiangChi:Array<majiang.Views.MajiangBtn> = [];  //游戏时的未使用牌池
        static randomQuePai:number;
    }

    /**
     * shengyuPai
     */
    export class PaiChi {
        public chi:Array<number>;

        public constructor(){
            this.chi = [];
        }
        /**
         * 重置牌池
         */
        public initPai(){
            this.chi = [];
            for (var index = 1; index < 10; index++) {
                for (var i = 0; i < 4; i++) {
                    if(majiang.Datas.Playing.randomQuePai != 1){
                        this.chi.push(index+10);
                    }
                    if(majiang.Datas.Playing.randomQuePai != 2){
                        this.chi.push(index+20);
                    }
                    if(majiang.Datas.Playing.randomQuePai != 3){
                        this.chi.push(index+30);
                    }
                }
            }
        }

        public removeAllPai(){
            this.chi = [];
        }

        public addPai(id:number){
            this.chi.push(id);
        }

        public getPai():number{
            // console.log("shiyong:",majiang.Datas.Playing.shiyongPai.chi);
            // console.log("shengyu:",majiang.Datas.Playing.shengyuPai.chi);

            if (this.chi.length < 1) {
                this.chi = majiang.Datas.Playing.shiyongPai.chi.slice(0);
                majiang.Datas.Playing.shiyongPai.chi = [];
            }

            if(this.chi.length === 1){
                return this.chi.shift();
            }
            var random:number = Math.floor( Math.random() * this.chi.length );
            return this.chi.splice(random,1)[0];
        }
    }
}